package org.friping.mytool.views.custom.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;

import org.androidannotations.annotations.EBean;
import org.friping.mytool.R;

import java.util.Map;

@EBean
public class RadioAdapter extends AppAdapter {

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = inflater.inflate(R.layout.it_radio_select, null);
        }

        Map itemData = (Map) this.getItem(position);
        TextView titleView = (TextView) convertView.findViewById(R.id.title);
        RadioButton radioButton = (RadioButton) convertView.findViewById(R.id.radioButton);
        String title = (String) itemData.getOrDefault("title", "");
        if(title.length() == 0){
            title = (String) itemData.getOrDefault("name", "");
        }
        titleView.setText(title);
        radioButton.setChecked(Boolean.TRUE.equals(itemData.get("checked")));

        return convertView;
    }
}
